/*
 * BSM6.0
 *
 * Copyright 2012-2013 (C) SINODATA CO., LTD. All Rights Reserved.
 */
package com.sinodata.bsm.itip.util;

import java.util.List;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

/**
 * <p>
 * Description: 把Soap的返回XML结果 转为字符串
 * </p>
 *
 * @author wangyazhou
 * @version 1.0

 * <p>
 * History: 
 *
 * Date                     Author         Version     Description
 * ---------------------------------------------------------------------------------
 * 2012-8-9 上午11:22:15          wangyazhou        1.0         To create
 * </p>
 *
 * @since 
 * @see     
 */
public class SoapUtil {

    @SuppressWarnings("unchecked")
    public static String[] convertSaopXmlToString(String xml) {
        String[] stry;
        try {
            Document doc = DocumentHelper.parseText(xml);
            List<Element> list = doc.selectNodes("/*/*/*/*/*/*/*");
            if (list == null || list.size() == 0) {
                return null;
            }
            stry = new String[list.size()];
            for (int i = 0; i < list.size(); i++) {
                Element e = list.get(i);
                stry[i] = e.getTextTrim();
            }
            return stry;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) {
        if (System.getProperty("javax.xml.parsers.SAXParserFactory") == null) {
            System.setProperty("javax.xml.parsers.SAXParserFactory", "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl");
        }
        convertSaopXmlToString("");
    }
}
